using UnityEngine;
using System.Collections;

public class Bullet : MonoBehaviour {
	
	public float speed;
	private int damage;
	private GameObject target;
	
	public void setup (GameObject target, int dmg)
	{
		this.damage = dmg;
		this.target = target;
	}
	
	void Start () 
	{
		Destroy (gameObject, 2);
		transform.LookAt(new Vector3(target.transform.position.x, transform.position.y, target.transform.position.z));
	}
	
	void Update () 
	{
	
		transform.Translate(Vector3.forward * speed * Time.deltaTime);
		
	}
	
	void OnTriggerEnter (Collider other) 
	{
		if (other.CompareTag("enemy1"))
		{
			Destroy (gameObject);
			Enemy temp = target.GetComponent<Enemy>();
			temp.Hit(damage);
		}
	}
}
